include ../../config.make

CFLAGS  = -I../../include/ \
		  -DLUA_USE_LINUX \
		  -O2 -Wall -Wl,-E
LDFLAGS = -ldl \
		  -lreadline \
		  -lhistory \
		  -lncurses

SRC  = $(wildcard *.c)
OBJ  = $(SRC:.c=.o)
LOBJ = $(filter-out lua%, $(OBJ))

LIB  = ../../lib/liblua.so
LUA  = ../../bin/lua
LUAC = ../../bin/luac

#################
## MAKE TARGET ##
#################

all: $(LIB) $(LUA) $(LUAC)

$(LUA): lua.o $(LOBJ)
	$(CC) $(CFLAGS) $(LDFLAGS) -L../../lib -llua -o $@ $^

$(LUAC): luac.o $(LOBJ)
	$(CC) $(CFLAGS) $(LDFLAGS) -L../../lib -llua -o $@ $^

$(LIB): $(LOBJ)
	$(CXX) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^

%.o: %.c
	$(CC) $(CFLAGS) -o $@ -c $<

clean:
	$(RM) *.o

mrproper: clean
	$(RM) $(LIB) $(LUA) $(LUAC)

